<%--
公司等待竞单的列表
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%pageContext.setAttribute("APP_PATH", request.getContextPath());%>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta charset="utf-8" />
    <title>维修公司</title>

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">


    <link rel="stylesheet" href="${APP_PATH}/recourse/css/login.css">
    <script type="text/javascript" src="${APP_PATH }/assets/js/xadmin.js"></script>

    <link rel="stylesheet" href="${APP_PATH }/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${APP_PATH }/recourse/css/formSelects-v4.css"/>

    <script type="text/javascript" src="${APP_PATH }/layui/layui.all.js"></script>
    <script type="text/javascript" src="${APP_PATH }/layui/lay/modules/layer.js"></script>

    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <!-- bootstrap & fontawesome -->
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
    <style>
        @import url(https://fonts.googleapis.com/css?family=Open+Sans);
        body {
            padding: 20px;
            font: 1.4em/1.4em 'Open Sans', sans-serif;
        }
        .module {
            width: 450px;
            margin: 0 0 1em 0;
            overflow: hidden;
        }
        .module p {
            margin: 0;
        }

        .line-clamp {
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
        }

        .fade {
            position: relative;
            height: 3.6em; /* exactly three lines */
        }
        .fade:after {
            content: "";
            text-align: right;
            position: absolute;
            bottom: 0;
            right: 0;
            width: 70%;
            height: 1.2em;
            background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 50%);
        }

        .ftellipsis {
            height: 3.6em;
        }

        h1 {
            margin: 0 0 1em 0;
        }
        h2 {
            font-size: 1.2em;
        }

    </style>

</head>
<body >
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li class="layui-this">基本信息</li>
        <li id="bg_one">报修审核</li>
        <li id="bg_two">报价审核</li>
        <li id="bg_three">竞单发布/报价</li>
        <li id="bg_four">图片信息</li>
        <li id="bg_five">视频信息</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <table width="650" height="380"  border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td><b>维修单名称：</b>${order.order_name}</td>
                    <td><b>维修单编号：</b>${order.id}</td>
                </tr>
                <tr>
                    <td><b>维修单目前状态：</b>${order.state_name}</td>
                    <td><b>报修人员：</b>${order.equipment_admin_name}</td>
                </tr>
                <tr>
                    <td><b>维修单所属部门：</b>${order.department_id==1?"营房":(order.department_id==2?"装备":"公共")}</td>
                    <td><b>维修单拟定价格：</b>${order.second_price}元</td>
                </tr>
                <tr>
                    <td><b>维修单发起时间：</b><fmt:formatDate value="${order.createTime}" type="date"/></td>
                    <td><b>设备管理员维修要求：</b>${a.equals("")?(f.equals("")?"无":f):a}</td>
                </tr>
                <tr>
                    <td><b>审核员维修要求：</b>${b.equals("")?"无":b}</td>
                </tr>
            </table>
            <table width="650" height="150"  border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td colspan="2"><b>审批员意见</b></td>
                </tr>
                <tr>
                    <td style="width: 80%; height: 4vh">
                    <c:forEach items="${review_advice}" var="second_reviewerAdvice">
                        ${second_reviewerAdvice.detail}&nbsp;&nbsp;&nbsp;
                        <fmt:formatDate value="${second_reviewerAdvice.finished_time}" type="both" pattern="yyyy-MM-dd"/>&nbsp;&nbsp;&nbsp;<c:if test="${second_reviewerAdvice.reason != null && second_reviewerAdvice.reason != ''}">理由为：${second_reviewerAdvice.reason}</c:if><br/>
                    </c:forEach></td>
                </tr>
                <tr>
                    <td>
                        <b>维修问题表述：</b><br>
                    </td>
                </tr>
            </table>
            <div  class="module line-clamp" style="background-color: #F5F5F5 ;height: 80px;width: 700px">
                ${order.problem_word}
            </div>
            <hr/>
        </div>
        <div class="layui-tab-item">
            <div class="layui-form-item">
            <label class="layui-form-label">理由框</label>
            <div class="layui-input-block" style="width: 320px;margin-left: 80px">
                <select id = "s1" name="s1" lay-verify="required">
                        <option value="维修价格不合理">
                            维修价格不合理
                        </option>
                        <option value="不符合维修需求">
                            不符合维修需求
                        </option>
                        <option value="维修信息不全">
                            维修信息不全
                        </option>
                        <option value="其他原因">
                            其他原因
                        </option>
                </select>
            </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">审批员</label>
                <div class="layui-input-block" style="width: 320px;margin-left: 80px">
                    <select name="review" id="review" lay-filter="review" xm-select="review" xm-select-type="1" multiple="true">
                        <option value="">
                            无
                        </option>
                        <c:forEach items="${user_review}" var="option">
                            <option value="${option.id}">
                                    ${option.name}
                            </option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
            <label class="layui-form-label">价&格</label>
                <div class="layui-input-inline">
                    <input type="text" id="second_price" name = "second_price" required lay-verify="required" placeholder="请输入拟定价格" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">元</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">要&求</label>
                <div class="layui-input-inline" style="width: 320px">
                    <textarea id="request_state" name="request_state" placeholder="请输入内容" class="layui-textarea" ></textarea>
                </div>
            </div>
            <br>
            <button id="tre"  class="layui-btn layui-btn-radius layui-btn-normal" type="submit" style="margin-left: 180px"><i class="layui-icon">&#xe681</i>上级报修审批</button>
            <button id="reject" class="layui-btn layui-btn-radius layui-btn-danger" type="submit" style="margin-left: 40px">驳回报修</button>
        </div>

        <div class="layui-tab-item">
            <p>
                竞单/报价公司：${order.unit_name}
            </p>
            <br>
            <p>
                竞单价格/报价：${bid.estimated_price}元
            </p>
            <br>
            <p>
                开始维修时间：<fmt:formatDate value="${bid.start_time}" type="date"/>
            </p>
            <br>
            <p>
               结束维修时间：<fmt:formatDate value="${bid.finished_time}" type="date"/>
            </p>
            <br>
            <p>
                竞单/报价有效期：${order.biddingPeriodOfValidity}天
            </p>
            <br>
            <p>
                预估维修清单:<br><br>
                <c:forEach items="${list_e}" var="expense_detail">
                    耗材名称：${expense_detail.consumable_name}&nbsp;&nbsp;耗材数量(个)：${expense_detail.consumable_num}&nbsp;&nbsp;耗材单价(元)：${expense_detail.consumable_price}<br/>
                </c:forEach>
            </p>
            <br>
            <p>维修公司陈述:</p>
            <div  class="module line-clamp" style="background-color: #F5F5F5 ;height: 80px;width: 700px">
                ${bid.bidding_description}
            </div>
            <div class="layui-form-item">

            </div>
            <br>
            <button id="affirm" class="layui-btn layui-btn-radius" type="submit" style="margin-left: 80px;">确认通过</button>&nbsp;&nbsp;
            <button id="rebid" class="layui-btn layui-btn-radius layui-btn-warm" type="submit" >重新开始竞单</button>
        </div>

        <div class="layui-tab-item">
            <div class="layui-form-item" style="margin-left: 45px">
            <label class="layui-form-label">维修方</label>
            <div class="layui-input-block" style="width: 320px;margin-left: 90px">
                <select id="attribute" name="attribute" lay-verify="required">
                    <option value="">
                        无
                    </option>
                    <c:forEach items="${users}" var="option">
                        <option value="${option.id}">
                                ${option.name}(${option.tel})
                        </option>
                    </c:forEach>
                </select>
            </div>
            </div>
            <div id ="s_price" class="layui-form-item">
                <label class="layui-form-label" style="width: 135px;">拟定报价</label>
                <div class="layui-input-inline">
                    <input type="text" id="price" name = "price" required lay-verify="required" placeholder="" value="${order.second_price}" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">元</div>
            </div>
            <div id ="request" class="layui-form-item">
                <label class="layui-form-label" style="width: 135px;">维修要求</label>
                <div class="layui-input-inline" style="width: 320px">
                    <textarea id="state" name="state" placeholder="请输入内容" class="layui-textarea" ></textarea>
                </div>
            </div>
            <div class="layui-form-item">
            <label class="layui-form-label" style="width: 135px;">竞单时间</label>
            <div class="layui-input-inline">
                <input type="text" id="stay_time" name = "stay_time" required lay-verify="required" placeholder="请输入竞单时间" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">天</div>
            </div>
            <br>

            <button id = "bid" class="layui-btn layui-btn-radius layui-btn-warm" style="margin-left: 130px">发布竞单/询价</button>&nbsp;

        </div>

        <div class="layui-tab-item">
            <br>
            <c:forEach items="${photoes}" var="list" varStatus="status">
                <div class="img">
                    <img border="12dp" src="/mmmsimage/${list}" alt="暂无图片信息" style="width: 220px;height: 220px;margin-left: 10px;">
                </div>
            </c:forEach>
            <br>
        </div>
        <div class="layui-tab-item">
            <br>
            <c:forEach items="${video}" var="list_v" varStatus="status">
            <video width="320" height="240" style="margin-left: 200px;" controls autoplay>
                <source src="/mmmsimage/${list_v}" type="video/mp4">
                <object data="/mmmsimage/${list_v}" width="380" height="260">
                    <embed width="320" height="240" src="/mmmsimage/${list_v}">
                </object>
            </video><br>
            </c:forEach>
        </div>
        </div>
    </div>
<input id = "id" type="hidden" name="id" value="${order.id}"/><br>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.min.js"></script>

<!-- 包括所有bootstrap的js插件或者可以根据需要使用的js插件调用　-->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<style type="text/css">
    .img{width: 900px;margin: 50px auto; overflow: hidden;}
    .img div{
        float: left;
        width:198px;
        margin-left: 20px;
    }
    .img div img{
        display: block;
        width: 100%;
    }
</style>
<script type="text/javascript" src="${APP_PATH }/recourse/js/formSelects-v4.js"></script>
<script type="text/javascript">
    //全局定义一次, 加载formSelects
    layui.config({
        base: '/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects-v4'
    });
    //加载模块
    layui.use(['jquery', 'formSelects'], function () {
        var formSelects = layui.formSelects;
    });
</script>

<script>

    function mykey()
    {
//如果输入不是0-9就无效bai
        if (event.keyCode<47 || event.keyCode>57)
            event.keyCode = 0;
    }
</script>
<script type="text/javascript">
    function prints(id,depart) {
        var mf=document.getElementById("select");
        if(depart===1){
            mf.action="${pageContext.request.contextPath}/approver/barracks";
        }else if(depart===2){
            mf.action=""
        }else{
            mf.action=""
        }

    }
    function a(){
        var price = document.getElementById("price").value;
        var time = document.getElementById("time").value;
        var state= document.getElementById("state").value;
        if(price==="" || time === ""||state==="") {
            alert("请将价格，竞单简述，时间输入完整");
        }else{

        }
    }
</script>
<script type="text/javascript">
    function fag(video) {
        if(video!==""){
            location.href="/mmmsimage/${order.problem_video}";
        }
        else{
            location.href="${pageContext.request.contextPath}/error";
        }
    }

</script>

<script>

    layui.use(['form', 'layer', 'jquery', 'table', 'laydate', 'element', 'upload', 'flow'], function() {
        var layer = layui.layer,
            $=layui.jquery;
        $(document).on('click','#tre',function(){
            var getName = layui.formSelects.value("review","valStr");//取值name数组
            var validrule = new Object();
            var id = document.getElementById("id").value;
            var state = document.getElementById("request_state").value;
            var test_price = document.getElementById("second_price");
            var price = document.getElementById("second_price").value;
            var people = document.getElementById("reviewer");
            if(state===""){
                layer.alert("请将价格和维修要求输入完整！");
                return false;
            }
            if(test_price.value!==""){
                if(! /^\d+(\.\d+)?$/.test(test_price.value)) {
                    layer.alert("价格输入格式不正确！");
                    test_price.focus();
                    test_price.select();
                    return false;
                }
                else{
                if(confirm("确定将维修单上报审批")){
                var completeData = {
                    "id":id,
                    "price":price,
                    "state":state,
                    "people":getName
                }
                 $.ajax({
                     url:"${pageContext.request.contextPath}/approver/sub_review",
                     type : "POST",
                     dataType:"json",
                     contentType : "application/json;charset=UTF-8",
                     data: JSON.stringify(completeData),
                     success:function(data) {

                     }
                 });
                    layer.alert("提交成功", {
                            icon: 6
                        },
                        function() {
                            //关闭当前frame
                            xadmin.close();

                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });
                }else{
                    return false;
                }
            }
            }
    });
    });

    //报修驳回
    layui.use(['layer'], function() {
        var layer = layui.layer,
            $ = layui.jquery;
        $(document).on('click', '#reject', function () {
            var text = document.getElementById("s1").value;
            var id = document.getElementById("id").value;
            var completeData = {
                "id":id,
                "text":text
            };
            if(confirm("是否驳回该报修维修单？")){
            $.ajax({
                url:"${pageContext.request.contextPath}/approver/orderback",
                type : "POST",
                dataType:"json",
                contentType : "application/json;charset=UTF-8",
                data: JSON.stringify(completeData),
                success:function(data) {

                }
            });
                layer.alert("驳回成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();

                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
        }else{
            return false;
        }

        });
    });

    //指派任务
    layui.use(['layer'], function() {
        var layer = layui.layer,
            $ = layui.jquery;
        $(document).on('click', '#assign', function () {
            var people = document.getElementById("attribute");
            var t = people.options[people.selectedIndex].innerText;
            var x = document.getElementById("attribute").value;
            var id = document.getElementById("id").value;
            var test_price = document.getElementById("price");
            var price = document.getElementById("price").value;
            var state = document.getElementById("state").value;
            if(! /^\d+(\.\d+)?$/.test(test_price.value)){
                layer.alert("价格输入格式不正确！");
                test_price.focus();
                test_price.select();
                return false;
            }else{
                var completeData = {
                "id":id,
                "people":x,
                "price":price,
                "state":state
                };
            if(confirm("是否将任务提交给"+x+t.trim()+"完成")){
                $.ajax({
                    url:"${pageContext.request.contextPath}/approver/selectPeople",
                    type : "POST",
                    dataType:"json",
                    contentType : "application/json;charset=UTF-8",
                    data: JSON.stringify(completeData),
                    success:function(data) {
                    }
                });
                layer.alert("操作成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();
                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
            }else{
                return false;
            }
            }
        });

    });
    //发布竞单
    layui.use(['layer'], function() {
        var layer = layui.layer,
            $ = layui.jquery;
        $(document).on('click', '#bid', function () {
            var id = document.getElementById("id").value;
            var day = document.getElementById("stay_time").value;
            var test_time = document.getElementById("stay_time");
            var price = document.getElementById("price").value;
            var state = document.getElementById("state").value;
            var x = document.getElementById("attribute").value;
            if(!/^[0-9]*[1-9][0-9]*$/.test(test_time.value)){
                layer.alert("竞单时间输入格式不正确！");
                test_time.focus();
                test_time.select();
                return false;
            }else{
            var completeData = {
                "id":id,
                "day":day,
                "price":price,
                "state":state,
                "people":x
            }
            if(confirm("是否将此维修单发布为竞单")){
                $.ajax({
                    url:"${pageContext.request.contextPath}/approver/bidingOrder",
                    type : "POST",
                    dataType:"json",
                    contentType : "application/json;charset=UTF-8",
                    data: JSON.stringify(completeData),
                    success:function(data) {
                    }
                });
                layer.alert("操作成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();

                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
            }else{
                return false;
            }
            }
        });
    });
    //预估报价
    layui.use(['layer'], function() {
        var layer = layui.layer,
            $ = layui.jquery;
        $(document).on('click', '#pre_compute', function () {
            var people = document.getElementById("attribute");
            var t = people.options[people.selectedIndex].innerText;
            var x = document.getElementById("attribute").value;
            var id = document.getElementById("id").value;
            var test_price = document.getElementById("price");
            var price = document.getElementById("price").value;
            var state = document.getElementById("state").value;
            if(! /^\d+(\.\d+)?$/.test(test_price.value)){
                layer.alert("价格输入格式不正确！");
                test_price.focus();
                test_price.select();
                return false;
            }else{
                var completeData = {
                    "id":id,
                    "people":x,
                    "price":price,
                    "state":state
                };
                if(confirm("是否将任务提交给"+x+t.trim()+"完成")){
                    $.ajax({
                        url:"${pageContext.request.contextPath}/approver/precompute",
                        type : "POST",
                        dataType:"json",
                        contentType : "application/json;charset=UTF-8",
                        data: JSON.stringify(completeData),
                        success:function(data) {
                        }
                    });
                    layer.alert("操作成功", {
                            icon: 6
                        },
                        function() {
                            //关闭当前frame
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });
                }else{
                    return false;
                }
            }
        });

    });
    //竞单提交审批
    layui.use(['layer'], function() {
        var layer = layui.layer,
            $ = layui.jquery;
        $(document).on('click', '#bid_review', function () {
            var people = document.getElementById("reviewer2");
            var x =document.getElementById("reviewer2").value;
            var t = people.options[people.selectedIndex].innerText;
            var id = document.getElementById("id").value;
            var completeData = {
                "id":id,
                "people":x
            }
            if(confirm("是否将此维修单提交给审批员"+t.trim())){
                $.ajax({
                    url:"${pageContext.request.contextPath}/approver/bid_reviewer",
                    type : "POST",
                    dataType:"json",
                    contentType : "application/json;charset=UTF-8",
                    data: JSON.stringify(completeData),
                    success:function(data) {
                    }
                });
                layer.alert("操作成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();
                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
            }else{
                return false;
            }

        });
    });
    //确认通过
    layui.use(['layer'], function() {
        var layer = layui.layer,
            $ = layui.jquery;
        $(document).on('click', '#affirm', function () {
            var id = document.getElementById("id").value;
            var completeData = {
                "id":id,
            }
            if(confirm("是否通过此维修单?")){
                $.ajax({
                    url:"${pageContext.request.contextPath}/approver/affirm_approve",
                    type : "POST",
                    dataType:"json",
                    contentType : "application/json;charset=UTF-8",
                    data: JSON.stringify(completeData),
                    success:function(data) {
                    }
                });
                layer.alert("操作成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();
                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
            }else{
                return false;
            }

        });
    });

    //重新开始竞单
    layui.use(['layer'], function() {
        var layer = layui.layer,
            $ = layui.jquery;
        $(document).on('click', '#rebid', function () {
            var id = document.getElementById("id").value;
            var completeData = {
                "id":id
            };
            if(confirm("是否通过此维修单?")){
                $.ajax({
                    url:"${pageContext.request.contextPath}/approver/rebid",
                    type : "POST",
                    dataType:"json",
                    contentType : "application/json;charset=UTF-8",
                    data: JSON.stringify(completeData),
                    success:function(data) {
                    }
                });
                layer.alert("操作成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();
                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
            }else{
                return false;
            }
        });
    });

</script>

<script>
    window.onload =function() {
       var state = ${order.order_state};
       var video = ${video.size()};
       if(state === 1){
            document.getElementById("bg_two").style.display="none";
        }
        if(state === 1){
            document.getElementById("bg_two").style.display="none";
        }
        if(!(state === 1)){
            document.getElementById("bg_three").style.display="none";
            document.getElementById("bg_one").style.display="none";
        }
        if(!(state===13)){
            document.getElementById("bg_two").style.display="none";
        }
        if(video===0){
            document.getElementById("bg_five").style.display="none";
        }
    }

</script>
</body>

</html>




